# -*- coding: utf-8 -*-

"""
上传大文件

方法：

HTTPConnection class in httplib.py（Python 2.7）：

def send(self, data):
    \"""Send `data' to the server.\"""
    if self.sock is None:
        if self.auto_open:
            self.connect()
        else:
            raise NotConnected()

    if self.debuglevel > 0:
        print "send:", repr(data)
    blocksize = 8192
    if hasattr(data,'read') and not isinstance(data, array):
        if self.debuglevel > 0: print "sendIng a read()able"
        datablock = data.read(blocksize)
        while datablock:
            self.sock.sendall(datablock)
            datablock = data.read(blocksize)
    else:
        self.sock.sendall(data)
"""

import os
import urllib2
from settings import URL, BIG_FILE_PATH

with open(BIG_FILE_PATH, 'rb') as f
    req = urllib2.Request(URL, f.read())
    req.add_header("Content-Type", "application/zip")
    resp = urllib2.urlopen(request)

    resp = urllib2.urlopen(url, f, {
        # urllib2 will call len() on the data, which file objects don't support
        'Content-Length' : os.path.getsize(filename),
    })
